package demo;
//动物父类
class Animal {
    protected String name;
    protected int age;

    public Animal(String name,int age){
        this.name=name;
        this.age=age;
    }
    public void eat(){
        System.out.println("吃饭！");
    }
    public void sleep(){
        System.out.println("睡觉!");
    }
}
//狗子类继承动物类
class Dog extends Animal{
    public Dog(String name,int age){
        super(name,age);
    }
    public void eat(){
        System.out.println("吃骨头啦！");
    }
    public void sleep(){
        System.out.println("睡觉呼呼呼!");
    }
}
//猫子类继承动物类

class Cat extends Animal{
    public Cat(String name,int age){
       super(name,age);
    }
    public void eat(){
        System.out.println("吃鱼！");
    }
    public void sleep(){
        System.out.println("睡觉ZZZ~~~!");
    }
}
//多态实现
public class Test {
    public static void eat(Animal a) {
        a.eat();
    }
    public static void main(String[] args) {
        Dog dog=new Dog("大胖",3);
        Cat cat=new Cat("阿毛",2);
        eat(dog);
        eat(cat);
    }
}
